package br.com.fpf.pontoapp.model.dao.impl;

import android.content.ContentValues;
import android.database.Cursor;
import br.com.fpf.pontoapp.model.dao.IWorDayDAO;
import br.com.fpf.pontoapp.model.db.impl.Table;
import br.com.fpf.pontoapp.model.entity.WorkDay;

public class WorkDayDAO extends AbstractDAO<WorkDay> implements IWorDayDAO {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public WorkDayDAO() {
		super(Table.WORK_DAY.getName());
	}

	@Override
	protected WorkDay cursorToObject(Cursor cursor) {
		WorkDay workDay = new WorkDay();

		int column = cursor.getColumnIndex(WorkDay.ID_COLUMN);
		if (column > 0) {
			workDay.setId(cursor.getLong(column));
		}

		column = cursor.getColumnIndex(WorkDay.ID_USER);
		if (column > 0) {
			workDay.setIdUser(cursor.getLong(column));
		}

		column = cursor.getColumnIndex(WorkDay.ID_BEAT_POINT);
		if (column > 0) {
			workDay.setIdBeatPoint(cursor.getLong(column));
		}

		column = cursor.getColumnIndex(WorkDay.DT_WORK_DAY);
		if (column > 0) {
			workDay.setDtWorkDay(cursor.getString(column));
		}

		column = cursor.getColumnIndex(WorkDay.OCURRENCE);
		if (column > 0) {
			workDay.setOccurrence(cursor.getInt(column));
		}

		return workDay;
	}

	@Override
	protected ContentValues objectToContentValues(WorkDay entity) {

		final ContentValues values = new ContentValues();

		if (entity.getIdUser() > 0) {
			values.put(WorkDay.ID_USER, entity.getIdUser());
		}

		if (entity.getIdBeatPoint() > 0) {
			values.put(WorkDay.ID_BEAT_POINT, entity.getIdBeatPoint());
		}

		if (entity.getDtWorkDay() != null) {
			values.put(WorkDay.DT_WORK_DAY, entity.getDtWorkDay());
		}

		if (entity.getOccurrence() > 0) {
			values.put(WorkDay.OCURRENCE, entity.getOccurrence());
		}

		return values;
	}

}
